#include "glDepthStencil.h"

void glSetDepthStencilState(const GL_DEPTH_STENCIL_DESC *pDesc, uint32 StencilRef)
{
    if (pDesc == NULL)
        return;

    if (pDesc->DepthEnable)
    {
        glEnable(GL_DEPTH_TEST);
        glDepthFunc(pDesc->DepthFunc);
        glDepthMask(pDesc->DepthWriteMask);
    }
    else
        glDisable(GL_DEPTH_TEST);

    if (pDesc->StencilEnable)
    {
        glEnable(GL_STENCIL_TEST);
        glStencilMask(pDesc->StencilWriteMask);
        glStencilFunc(pDesc->FrontFace.StencilFunc, 
                      StencilRef, 
                      pDesc->StencilReadMask);
        glStencilOp(pDesc->FrontFace.StencilFailOp, 
                    pDesc->FrontFace.StencilDepthFailOp, 
                    pDesc->FrontFace.StencilPassOp);
    }
    else
        glDisable(GL_STENCIL_TEST);
}